package com.tjsinfo.tjsoa.workTask.action;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.workTask.bo.ITDailyWorkTaskBO;
import com.tjsinfo.tjsoa.workTask.vo.TDailyWorkTask;

public class WorkTaskUpdateAction extends Action {
	private ITDailyWorkTaskBO workTaskBo;
	
	public void setWorkTaskBo(ITDailyWorkTaskBO workTaskBo) {
		this.workTaskBo = workTaskBo;
	}
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		try {		
			Date date = new Date();
			
			Integer status = Integer.valueOf(request.getParameter("status")).intValue();         //状态：0未查看、1查看、2办结、3拒绝、4重办、5完结、6转发、7删除
			String id = request.getParameter("id");
			String method = request.getParameter("method");
			TDailyWorkTask tdwt = workTaskBo.findById(id);
			tdwt.setCurrentStatus(status);
			if(status==2 || status==3){
				tdwt.setRecipientFeedback(request.getParameter("recipientFeedback"));
				tdwt.setFeedbackTime(date);
			}else{
				if(status == 4){
					tdwt.setBack(1);
				}
				tdwt.setDividerOpinion(request.getParameter("dividerOpinion"));
				tdwt.setOpinionTime(date);
			}
			workTaskBo.update(tdwt);			
			
			request.setAttribute("linkurl", "daily/workTask/workTaskList.jsp?dividerUserid="+method);
			request.setAttribute("message", "system.save.message");
			return mapping.findForward("success");
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			request.setAttribute("Exception", e);
			return mapping.findForward("failed");
		}
	}
}
